package com.study.hot.jetpack.navigation;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

/**
 * <pre>
 *     author : fauks
 *     time   : 2020/03/31
 *     desc   :
 * </pre>
 */
public class GoodsViewModel extends ViewModel {
    private MutableLiveData<Integer> numbers;

    public MutableLiveData<Integer> getNumbers() {
        if (numbers == null) {
            numbers = new MutableLiveData<>();
            numbers.setValue(0);
        }
        return numbers;
    }

    public void add(int x) {
        numbers.setValue(numbers.getValue() + x);
        if (numbers.getValue() <= 0) {
            numbers.setValue(0);
        }
    }
}
